package com.weizai.carshop.controller;

import com.weizai.carshop.common.enumeration.AppHttpCodeEnum;
import com.weizai.carshop.common.result.PageResult;
import com.weizai.carshop.common.result.ResponseResult;
import com.weizai.carshop.model.dto.SetSideShowDto;
import com.weizai.carshop.model.entiity.SlideshowEntity;
import com.weizai.carshop.service.SideShowService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "后台管理系统--轮播图")
@RestController
@RequestMapping("/api/v1/admin")
public class SideShowController {

    @Autowired
    private SideShowService sideShowService;

    /**
     * 轮播图列表
     */
    @GetMapping("/swiperList")
    public ResponseResult list(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize){
        PageResult result = sideShowService.getSideShowList(page,pageSize);
        return ResponseResult.okResult(result);
    }


    /**
     * 轮播图新增或新增
     */
    @PostMapping("/setSwiper")
    public ResponseResult add(@RequestBody  SetSideShowDto setSideShowDto){
        sideShowService.setSwiper(setSideShowDto);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
    /**
     * 轮播图删除
     */
    @DeleteMapping("/delSwiper/{id}")
    public ResponseResult del(@PathVariable Long id){
        sideShowService.removeById(id);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
